//
//  OTDR_TestDetailInfoView.m
//  OTDR
//
//  Created by Liu on 2024/6/17.
//

#import "OTDR_TestDetailInfoView.h"
#import "OTDR_TestDetailInfoCell.h"

@interface OTDR_TestDetailInfoView ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic ,strong)UITableView *tableView;
@end
@implementation OTDR_TestDetailInfoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}


- (void )creatUI{
    [self addSubview:self.tableView];
    
}

#pragma mark -- tableView
-(UITableView *)tableView{
    if (!_tableView) {
        CGFloat contentWidth = SCREEN_HEIGHT-[UIApplication sharedApplication].keyWindow.safeAreaInsets.top-[UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom-SIZE(20);
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake([UIApplication sharedApplication].keyWindow.safeAreaInsets.top, 0, contentWidth, SCREEN_WIDTH) style:UITableViewStyleGrouped];
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
        _tableView.backgroundColor = kWhiteColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate   = self;
        _tableView.dataSource = self;
        _tableView.estimatedRowHeight = 50;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        if (@available(iOS 11.0,*)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
        }
        [_tableView registerClass:[OTDR_TestDetailInfoCell class] forCellReuseIdentifier:@"OTDR_TestDetailInfoCell"];
    }
    return _tableView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.tableDataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OTDR_TestDetailInfoCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"OTDR_TestDetailInfoCell" forIndexPath:indexPath];
    NSDictionary *dic = self.tableDataArray[indexPath.row];
    cell.la1.text = [NSString stringWithFormat:@"%d",[dic[@"index"] intValue]];
    
    NSString *imgName = @"";
    int  style = [dic[@"event_style"] intValue];
    if (style == 0) {
        imgName = @"eventstart";
    } else if (style == 1) {
        imgName = @"eventref";
    } else if (style == 2) {
        imgName = @"eventdown";
    } else if (style == 3) {
        imgName = @"eventend";
    } else if (style == 4) {
        imgName = @"eventup";
    } else if (style == 5) {
        imgName = @"eventbend";
    } else {
        imgName = @"eventstart";
    }
    cell.la2.image = [UIImage imageNamed:imgName];
    cell.la3.text = [NSString stringWithFormat:@"%@",dic[@"receevent_Dis"]];
    cell.la4.text = [NSString stringWithFormat:@"%@",dic[@"receevent_Ave"]];
    cell.la5.text = [NSString stringWithFormat:@"%@",dic[@"receevent_Con"]];
    cell.la6.text = [NSString stringWithFormat:@"%@",dic[@"receevent_Ref"]];
    cell.la7.text = [NSString stringWithFormat:@"%@",dic[@"receevent_link"]];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return SIZE(45);
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //内容区最大宽度
    CGFloat contentWidth = self.bounds.size.width-[UIApplication sharedApplication].keyWindow.safeAreaInsets.top-[UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom-SIZE(20);
    UIView *view =  [ViewCreate createLineFrame:CGRectMake(0, 0, contentWidth, SIZE(45)) backgroundColor:[UIColor whiteColor]];
    //1、2区域宽度
    CGFloat widthAB = SIZE(45);
    CGFloat otherWidth = (contentWidth-SIZE(45)*2)/5.0;
    
    UILabel *la1 = [ViewCreate createLabelFrame:CGRectMake(0, 0, widthAB, widthAB) backgroundColor:kThemeColor text:@"" textColor:RGB51 textAlignment:Center font:FONT(17)];
    [view addSubview:la1];
    UILabel *la2 = [ViewCreate createLabelFrame:CGRectMake(widthAB, 0, widthAB, widthAB) backgroundColor:kThemeColor text:[LanguageTool DPLocalizedString:@"leixing"] textColor:RGB51 textAlignment:Center font:FONT(17)];
    [view addSubview:la2];
    
    UILabel *la3 = [ViewCreate createLabelFrame:CGRectMake(widthAB*2, 0, otherWidth, widthAB) backgroundColor:kThemeColor text:[LanguageTool DPLocalizedString:@"juli"] textColor:RGB51 textAlignment:Center font:FONT(17)];
    [view addSubview:la3];
    
    UILabel *la4 = [ViewCreate createLabelFrame:CGRectMake(widthAB*2+otherWidth, 0, otherWidth, widthAB) backgroundColor:kThemeColor text:[NSString stringWithFormat:@"%@(db/km)",[LanguageTool DPLocalizedString:@"shuaijian"]] textColor:RGB51 textAlignment:Center font:FONT(17)];
    [view addSubview:la4];
    
    UILabel *la5 = [ViewCreate createLabelFrame:CGRectMake(widthAB*2+otherWidth*2, 0, otherWidth, widthAB) backgroundColor:kThemeColor text:[NSString stringWithFormat:@"%@(dB)",[LanguageTool DPLocalizedString:@"sunhao"]] textColor:RGB51 textAlignment:Center font:FONT(17)];
    [view addSubview:la5];
    
    UILabel *la6 = [ViewCreate createLabelFrame:CGRectMake(widthAB*2+otherWidth*3, 0, otherWidth, widthAB) backgroundColor:kThemeColor text:[NSString stringWithFormat:@"%@(dB)",[LanguageTool DPLocalizedString:@"fanshe"]] textColor:RGB51 textAlignment:Center font:FONT(17)];
    [view addSubview:la6];
    
    UILabel *la7 = [ViewCreate createLabelFrame:CGRectMake(widthAB*2+otherWidth*4, 0, otherWidth, widthAB) backgroundColor:kThemeColor text:[NSString stringWithFormat:@"%@(dB)",[LanguageTool DPLocalizedString:@"leiji"]] textColor:RGB51 textAlignment:Center font:FONT(17)];
    [view addSubview:la7];
    
    return view;
}



@end
